package sdk.wufun.com.wfsdk_ysdk4switchpay;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;

import com.tencent.ysdk.api.YSDKApi;
import com.tencent.ysdk.framework.common.ePlatform;
import com.wufun.sdk.WFCode;
import com.wufun.sdk.WFSDK;
import com.wufun.sdk.log.Log;

/**
 * 选择QQ、微信登录方式
 */
public class ChooseLoginTypeActivity extends Activity {
	
	private View btnQQ;
	private View btnWX;
	private View btnGuest;
	
	@SuppressLint("NewApi") 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
				WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
		
		setFinishOnTouchOutside(false);
		
		int layoutID = 0;
		if(true){
			layoutID = getResources().getIdentifier("u8_layout_login_choice2", "layout", getPackageName());
			setContentView(layoutID);
			btnGuest = findViewById(getResources().getIdentifier("btn_guest", "id", getPackageName()));

		}else if(YSDK.isCustomLogin()){
			layoutID = getResources().getIdentifier("u8_custom_login_choice", "layout", getPackageName());
			setContentView(layoutID);
		}
		else{
			layoutID = getResources().getIdentifier("u8_layout_login_choice", "layout", getPackageName());
			setContentView(layoutID);
		}

		btnQQ = findViewById(getResources().getIdentifier("btn_qq", "id", getPackageName()));
		btnWX = findViewById(getResources().getIdentifier("btn_wx", "id", getPackageName()));



		btnQQ.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View arg0) {
				ChooseLoginTypeActivity.this.finish();
				//YSDK.login(YSDK.LOGIN_TYPE_QQ);

				if(YSDKApi.isPlatformInstalled(ePlatform.QQ)){
					YSDK.login(YSDK.LOGIN_TYPE_QQ);
				}else{
					WFSDK.getInstance().onResult(WFCode.CODE_LOGIN_FAIL, "login failed");
					YSDK.showTip("您还没有安装QQ，请先安装QQ");
				}

			}
		});
		btnWX.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View arg0) {
				ChooseLoginTypeActivity.this.finish();

				YSDK.login(YSDK.LOGIN_TYPE_WX);	//ysdk 1.4.0以上增加了扫码登录，不用判断微信客户端是否安装了

//				if(YSDKApi.isPlatformInstalled(ePlatform.WX)){
//					YSDK.login(YSDK.LOGIN_TYPE_WX);00
//				}else{
//					U8SDK.getInstance().onResult(U8Code.CODE_LOGIN_FAIL, "login failed");c
//					YSDK.showTip("您还没有安装微信，请先安装微信");
//				}

			}
		});

		if(btnGuest != null){

			btnGuest.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					ChooseLoginTypeActivity.this.finish();

					YSDK.login(YSDK.LOGIN_TYPE_GUEST);

				}
			});			
			
		}else{
			Log.w("U8SDK", "btnGuest is null");
		}
		
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		
	}
	
	public boolean onKeyDown(int keyCode, KeyEvent event){
		Log.d("U8SDK", "OnKeyDown:"+keyCode);
		if(keyCode == KeyEvent.KEYCODE_BACK){
			return true;
		}
		
		return super.onKeyDown(keyCode, event);
	}
	
}
